#include <iostream>

using namespace std;

class Complex {
	public:
		Complex() : m_real(0.0), m_imag(0.0) {}
		Complex(float real, float imag) : m_real(real), m_imag(imag) {}
		void show() {cout << m_real << "+" << m_imag << "i" << endl;}
		// 重载运算符
		Complex operator+(const Complex &c);
		Complex operator-(const Complex &c);
		Complex operator*(const float &n);
		Complex operator/(const float &n);
		friend Complex operator+=(Complex &a, const Complex &b);
		friend Complex operator-=(Complex &a, const Complex &b);
		friend bool operator==(const Complex &a, const Complex &b);
		friend bool operator!=(const Complex &a, const Complex &b);
		friend ostream &operator<<(ostream &out, const Complex &c);
		friend istream &operator>>(istream &in, Complex &c);

	private:
		float m_real;
		float m_imag;
};

Complex Complex::operator+(const Complex &c)
{
	Complex res;

	res.m_real = this->m_real + c.m_real;
	res.m_imag = this->m_imag + c.m_imag;

	return res;
}

Complex Complex::operator-(const Complex &c)
{
	Complex res;

	res.m_real = this->m_real - c.m_real;
	res.m_imag = this->m_imag - c.m_imag;

	return res;
}

Complex Complex::operator*(const float &n)
{
	Complex res;

	res.m_real = this->m_real * n;
	res.m_imag = this->m_imag * n;

	return res;
}

Complex Complex::operator/(const float &n)
{
	Complex res;

	res.m_real = this->m_real / n;
	res.m_imag = this->m_imag / n;

	return res;
}

Complex operator+=(Complex &a, const Complex &b)
{
	a.m_real += b.m_real;
	a.m_imag += b.m_imag;

	return a;
}

Complex operator-=(Complex &a, const Complex &b)
{
	a.m_real -= b.m_real;
	a.m_imag -= b.m_imag;

	return a;
}

bool operator==(const Complex &a, const Complex &b)
{
	return a.m_real == b.m_real && a.m_imag == b.m_imag;
}

bool operator!=(const Complex &a, const Complex &b)
{
	return a.m_real != b.m_real || a.m_imag != b.m_imag;
}

ostream &operator <<(ostream &out, const Complex &c)
{
	out << c.m_real << "+" << c.m_imag << "i";

	return out;
}

istream &operator >>(istream &in, Complex &c)
{
	in >> c.m_real >> c.m_imag;

	return in;
}

int main(void)
{
	Complex c1(1.2, 7.2);
	Complex c2;
	Complex c3;

	cout << "输入c2: ";
	cin >> c2;

	cout << "c1: " << c1 << ", c2: " << c2 << endl;

	c3 = c1 + c2;
	cout << "c3 = c1 + c2: " << c3 << endl;
	
	c3 = c1 - c2;
	cout << "c3 = c1 - c2: " << c3 << endl;

	c3 = c1 * 2;
	cout << "c3 = c1 * 2: " << c3 << endl;

	c3 += c2;
	cout << "c3 += c2: " << c3 << endl;

	return 0;
}

